package com.apes.scm.stock.inventory.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.stock.inventory.model.InventoryList;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface InventoryListRepository extends CustomRepository<InventoryList, String>{

    @Query(
         value = "SELECT T FROM InventoryList T WHERE T.state not in ('delete','done','review') and  T.warehouseId.id = ?1"
    )
    List<InventoryList> findInventoryListForPDA(String warehouseId);

    /**
     * fetch data by local Permit id and warehouseId
     *
     * @param localPermitId 本地权限id
     * @param warehouseId  仓库库区id
     * @return List<ProductReceive>
     */
    @Query(
            value = "SELECT T FROM InventoryList T WHERE T.state not in ('delete','done','review') and  T.warehouseId.id = ?1 " +
                    "and exists (select 1 from LocalPermitItem L where L.type.id='pt_location'  and T.warehouseId.id =L.orgId and L.localPermit.id =?2)"
    )
    List<InventoryList> findInventoryListBylocalPermitId(String warehouseId,String localPermitId);
}

